Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug restart #508

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

awisniew90
Copy link
Contributor

@awisniew90 awisniew90 commented May 8, 2024

Fixes #498

This PR creates the following behaviors:

  1. A Hot Code Replace failure will now prompt the user to "refresh" the debugger. This will result in the debugger being disconnected and reconnected
    2. A restart of the server from dev mode via the command line will result in the debugger being disconnected and reconnected when the server restarts (using whatever debug port dev mode chose)
    3. When in debug mode, the debugger is always on.... if disconnected (automatically or manually), it will always attempt to reconnect.

After reviewing, it seemed overkill to attempt to reconnect the debugger on every disconnect. This also created issues when intentionally disconnecting the debugger. In place of number 2 and 3 above, we are instead adding a "Connect Liberty Debugger" action to the Debug view context menu. If the debugger is disconnected (due to a restart of the server or manual disconnect), a user can now reconnect without having to stop and start the application via the Dashboard.

----- More Details ------

In the second rendition of the Liberty Tools debugger (prior to this PR), the debugger was combined with the Maven/devmode process into one launch configuration. This meant that the lifecycle of the two processes were tightly coupled causing undesired behavior. For example, a disconnect of the debugger triggered a full termination of the application running in Maven. 3 ways this disconnect could happen is either via a HCR failure, a restart of the server via devmode, or a manual disconnect via the debug view context menu.

This PR makes the following improvements:

  1. A custom HCR failure dialog is presented to the user with an option to restart the debugger. This does so without a restart to the Maven/devmode process.
  2. A new LibertyDebugTarget is used which overrides the default JDIDebugTarget disconnect behavior by not triggering a "terminate" of the launch (the root problem).
  3. Introduces a "Connect Liberty Debugger" action to the debug view context menu.

@scottkurz
Copy link
Member

This is a nice improvement on the HCR failure path.

Now that I appreciate the use case better... I can also appreciate that it still leaves say the path in which dev mode restarts the server upon a bootstrap.properties update.

Let's think about that more.

@awisniew90 awisniew90 force-pushed the debug-restart branch 5 times, most recently from cd61919 to 5ce2066 Compare July 12, 2024 14:46
/**
* Updates the state of this target for disconnection from the VM.
*/
@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment explaining we don't know here if we're disconnected() because of dev mode restarting the server vs. the JDT debugger HCR failure refreshing the debugger.

port = parts[1].trim();
String lastEntry = null;

Scanner scan = new Scanner(serverEnv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out we don't need to make this change.

@awisniew90 awisniew90 force-pushed the debug-restart branch 2 times, most recently from 5c608df to c95e3ee Compare August 20, 2024 17:27
Adam Wisniewski and others added 2 commits January 2, 2025 10:57
Signed-off-by: Adam Wisniewski <[email protected]>
@scottkurz
Copy link
Member

Just capturing that we reviewed this today and thought it'd be good to get rid of the automatic reconnect on disconnect. We can still have the overloaded reconnect selection button on HCR failure. We also are good with the idea that each Run/Debug config can define its own reconnect/disconnect behavior, so us defining our own is fine from that POV.

Signed-off-by: Adam Wisniewski <[email protected]>
Signed-off-by: Adam Wisniewski <[email protected]>
@awisniew90 awisniew90 marked this pull request as ready for review January 9, 2025 17:50
Signed-off-by: Adam Wisniewski <[email protected]>
Copy link
Member

@scottkurz scottkurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See what you think.

Path serverEnvPath = Paths.get(list.item(0).getTextContent(), "server.env");

// Make sure the server.env path exists. If not return null.
if (!Files.exists(serverEnvPath)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Now I realize this might be superseded by my idea to wrap all this in a retry)

if (debugPort == null) {
debugPort = port;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate how we guard this with the if (readDebugPort) flag and bypass reading the server.env file.

However, consider the case where we do a regular (non-debug) start/run, and then do a manual "Connect Liberty Debugger". If we do it too early, while dev mode is still starting, before the server is launched, then either reading the port from server.env, or even reading liberty-plugin-config.xml could fail.

Should we just add a sleep and retry on this path to handle this case?

If we can't, it might suggest we would then ideally want to disable to connect before the server is active. But maybe sleeping/retrying would be easier? WDYT?

}

// Remove old debug target
launch.removeDebugTarget((IDebugTarget) object);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed removeDebugTarget was spitting out a ClassCastException like:

java.lang.ClassCastException: class org.eclipse.debug.core.Launch cannot be cast to class org.eclipse.debug.core.model.IDebugTarget (org.eclipse.debug.core.Launch and org.eclipse.debug.core.model.IDebugTarget are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @2ee10074)

and presumably because of this the view wasn't looking as clean as ideally it would after doing disconnect and then (re)Connect

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restart (r) in dev mode kills the debugging session
2 participants